package com.yvan.serverless.utils;

import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import lombok.SneakyThrows;
import org.apache.commons.io.IOUtils;

import java.io.File;
import java.io.FileOutputStream;
import java.nio.charset.StandardCharsets;
import java.util.stream.Collectors;

public class OtherUtils {
    public static final OtherUtils INSTANCE = new OtherUtils();

    @SneakyThrows
    public void saveFile(String path, String content) {
        var file = new File(path);
        try (var out = new FileOutputStream(file)) {
            IOUtils.writeLines(
                    content.lines().collect(Collectors.toList()),
                    null,
                    out,
                    StandardCharsets.UTF_8);
        }
    }

    public String readFile(String path) {
        return FileUtilExt.readContent(new File(path));
    }

    public String normalizePath(Object... args) {
        return FileUtilExt.normalizePath(args);
    }

    public Long newId() {
        return IdWorker.getId();
    }
}
